package com.canplay.screen.db

import com.canplay.screen.init.appContext
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class DataLocateDataSource(private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO) {
    suspend fun getAllDate(): List<DataItem> {
        return withContext(ioDispatcher) {
            AppDatabase.getInstant(appContext).dataItemDao().getAllData();
        }
    }

    suspend fun insertItem(itemData: DataItem) {
        return withContext(ioDispatcher) {
            AppDatabase.getInstant(appContext).dataItemDao().insertItem(itemData);

        }
    }


    suspend fun insertAll(list: List<DataItem>) {
        return withContext(ioDispatcher) {
            AppDatabase.getInstant(appContext).dataItemDao().insertAllData(list);

        }
    }

    suspend fun deleteAll() {
        return withContext(ioDispatcher) {
            AppDatabase.getInstant(appContext).dataItemDao().deleteAllUsers();
        }
    }
}